// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-12-02

package edit

import (
	"gitee.com/gomq/sr"
	"gomq/app"
)

type Request struct {
	Id int `json:"id" validate:"required,min=1" label:"Task id"`

	Topic               sr.TopicName  `json:"topic" validate:"required,min=2,max=30" label:"Topic name"`
	Tag                 sr.TopicTag   `json:"tag" validate:"required,min=2,max=60" label:"Topic tag"`
	Concurrency         any           `json:"concurrency" validate:"min=1,max=1500" label:"Scheduler concurrency"`
	DelaySeconds        any           `json:"delay_seconds" validate:"omitempty,min=0,max=86400" label:"Delay seconds"`
	Threads             any           `json:"threads" validate:"min=1,max=50" label:"Task threads"`
	MaxRetry            any           `json:"max_retry" validate:"min=1,max=30" label:"Max retry"`
	Store               app.Status    `json:"store"`
	Title               string        `json:"title" validate:"required,min=2,max=90" label:"Task title"`
	Remark              string        `json:"remark"`
	ConditionExpression sr.Expression `json:"condition_expression"`

	Handler                   sr.Address    `json:"handler" validate:"required,min=7" label:"Task handler"`
	HandlerTimeout            any           `json:"handler_timeout" validate:"required,min=1,max=30" label:"Handler timeout"`
	HandlerMethod             sr.Method     `json:"handler_method" validate:"required" label:"Handler method"`
	HandlerFormat             sr.Format     `json:"handler_format" validate:"required" label:"Handler format"`
	HandlerResponseFormat     sr.Format     `json:"handler_response_format" validate:"required" label:"Response format"`
	HandlerResponseExpression sr.Expression `json:"handler_response_expression"`

	Failed                   sr.Address    `json:"failed"`
	FailedTimeout            any           `json:"failed_timeout" validate:"required,min=1,max=30" label:"Failed notifier timeout"`
	FailedMethod             sr.Method     `json:"failed_method" validate:"required" label:"Failed method timeout"`
	FailedResponseFormat     sr.Format     `json:"failed_response_format" validate:"required" label:"Failed response format"`
	FailedResponseExpression sr.Expression `json:"failed_response_expression"`

	Succeed                   sr.Address    `json:"succeed"`
	SucceedTimeout            any           `json:"succeed_timeout" validate:"required,min=1,max=30" label:"Succeed notifier timeout"`
	SucceedMethod             sr.Method     `json:"succeed_method" validate:"required" label:"Succeed method timeout"`
	SucceedResponseFormat     sr.Format     `json:"succeed_response_format" validate:"required" label:"Succeed response format"`
	SucceedResponseExpression sr.Expression `json:"succeed_response_expression"`
}

// func (o *Request) BeforeValidate() error {
//     log.Errorf(`------------------------ Validate before:`)
//     o.Concurrency = app.AnyInt32(o.Concurrency, 10)
//     o.DelaySeconds = app.AnyInt(o.DelaySeconds, 0)
//     o.Threads = app.AnyInt(o.Threads, 1)
//     o.MaxRetry = app.AnyInt(o.MaxRetry, 3)
//     o.HandlerTimeout = app.AnyInt(o.HandlerTimeout, 5)
//     o.FailedTimeout = app.AnyInt(o.FailedTimeout, 5)
//     o.SucceedTimeout = app.AnyInt(o.SucceedTimeout, 5)
//
//     log.Errorf(`------------------------ Validate After: concurrency="%v"`, o.Concurrency)
//     return nil
// }
